package cqrtplm.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ty.basic.response.ResponseResult;
import cqrtplm.constant.RouteConstant;
import cqrtplm.dto.query.EuEmissionsNOQueryDTO;
import cqrtplm.entity.RtCertFieldEuemissionsnoRelationDO;
import cqrtplm.service.RtCertFieldEuemissionsnoRelationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "认证-客户备案机型和欧排号关系")
@RequestMapping("/rest"+RouteConstant.RATO + "cert/fieldeuemissionsnorelation/" + "v1")
public class RtCertFieldEuemissionsnoRelationController {

    @Resource
    private RtCertFieldEuemissionsnoRelationService rtCertFieldEuemissionsnoRelationService;

    @PostMapping("/list")
    @ApiOperation("获取客户备案机型和欧排号关系列表")
    public ResponseResult list(@RequestBody RtCertFieldEuemissionsnoRelationDO rtCertFieldEuemissionsnoRelation) {
        List<RtCertFieldEuemissionsnoRelationDO> list = rtCertFieldEuemissionsnoRelationService
                .selectRtCertFieldEuemissionsnoRelationList(rtCertFieldEuemissionsnoRelation);
        return ResponseResult.success(list);
    }

    @PostMapping("/query")
    @ApiOperation("获取客户备案机型和欧排号关系列表")
    public ResponseResult query(@RequestBody EuEmissionsNOQueryDTO entity) {
        List<RtCertFieldEuemissionsnoRelationDO> list = rtCertFieldEuemissionsnoRelationService
                .queryRtCertFieldEuemissionsnoRelationList(entity);
        return ResponseResult.success(list);
    }


    @PostMapping("/pagelist")
    @ApiOperation("分页获取客户备案机型和欧排号关系列表")
    public ResponseResult<PageInfo<RtCertFieldEuemissionsnoRelationDO>> pagelist(
            @RequestBody RtCertFieldEuemissionsnoRelationDO rtCertFieldEuemissionsnoRelation,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "20") int pageSize) {
        PageHelper.startPage(page, pageSize);
        List<RtCertFieldEuemissionsnoRelationDO> list = rtCertFieldEuemissionsnoRelationService
                .selectRtCertFieldEuemissionsnoRelationList(rtCertFieldEuemissionsnoRelation);
        return ResponseResult.success(new PageInfo<>(list));
    }

    @GetMapping("/{id}")
    @ApiOperation("获取客户备案机型和欧排号关系详情")
    public ResponseResult getById(@PathVariable String id) {
        return ResponseResult.success(rtCertFieldEuemissionsnoRelationService
                                              .selectRtCertFieldEuemissionsnoRelationById(id));
    }

    @GetMapping("/relation")
    @ApiOperation("根据备案机型ID和客户ID获取关系")
    public ResponseResult getByFiledIdAndCustomId(
            @RequestParam String filedId,
            @RequestParam String customId) {
        return ResponseResult.success(rtCertFieldEuemissionsnoRelationService
                                              .selectRtCertFieldEuemissionsnoRelationByFiledIdAndCustomId(filedId, customId));
    }

    @PostMapping("/add")
    @ApiOperation("新增客户备案机型和欧排号关系")
    public ResponseResult add(@RequestBody RtCertFieldEuemissionsnoRelationDO rtCertFieldEuemissionsnoRelation) {
        return ResponseResult.success(rtCertFieldEuemissionsnoRelationService
                                              .insertRtCertFieldEuemissionsnoRelation(rtCertFieldEuemissionsnoRelation));
    }

    @PostMapping("/edit")
    @ApiOperation("修改客户备案机型和欧排号关系")
    public ResponseResult edit(@RequestBody RtCertFieldEuemissionsnoRelationDO rtCertFieldEuemissionsnoRelation) {
        return ResponseResult.success(rtCertFieldEuemissionsnoRelationService
                                              .updateRtCertFieldEuemissionsnoRelation(rtCertFieldEuemissionsnoRelation));
    }

    @PostMapping("/stop/{id}")
    @ApiOperation("停用客户备案机型和欧排号关系")
    public ResponseResult stop(@PathVariable String id) {
        return ResponseResult.success(rtCertFieldEuemissionsnoRelationService
                                              .stopRtCertFieldEuemissionsnoRelation(id));
    }

    @DeleteMapping("/del")
    @ApiOperation("删除客户备案机型和欧排号关系")
    public ResponseResult remove(@RequestBody List<String> ids) {
        return ResponseResult.success(rtCertFieldEuemissionsnoRelationService
                                              .deleteRtCertFieldEuemissionsnoRelationByIds(ids));
    }
}